using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
namespace GT.DataAccess
{
    partial class Document : DataAccess<GTDataContext, Document>
    {
        public Document(Guid documentID, string documentPath) : this()
        {
            DocumentID = documentID;
            DocumentPath = documentPath;
        }
        partial void OnCreated()
        {
            DataContext = GT.DataAccess.GTDataContext.Context;
        }
    }

    partial class GTDataContext
    {
        /// <summary>
        /// Đối tượng DataContext tĩnh.
        /// </summary>
        private static GTDataContext _context;
        public static GTDataContext Context
        {
            get
            {
                if (_context == null) _context = new GTDataContext();
                return _context;
            }
        }
    }

    partial class Node : DataAccess<GTDataContext, Node>
    {
        public Node(Guid nodeID, string nodeText, int numDocument, Node parentNode)
            : this()
        {
            NodeID = nodeID;
            NodeText = nodeText;
            NumDocument = numDocument;
            ParentNode = parentNode;
        }
        public static Node Get(Guid nodeID)
        {
			IEnumerable<Node> ie = (from x in GTDataContext.Context.Nodes where x.NodeID == nodeID select x);
			return (ie.Count() > 0) ? ie.First() : null;
        }
        public static Node Get(string nodeText, Guid parentID)
        {
			IEnumerable<Node> ie = (from x in GTDataContext.Context.Nodes where (x.NodeText == nodeText && x.ParentID == parentID) select x);
			return (ie.Count() > 0) ? ie.First() : null;
        }
		partial void OnCreated()
		{
			DataContext = GTDataContext.Context;
		}
    }
}
